package com.gycode.vpush.consumer.handler.base;


import java.util.UUID;

public abstract class AbstractHandler implements Handler {
    private static final ThreadLocal<String> logId = new ThreadLocal();
    private static final ThreadLocal<String> data = new ThreadLocal();

    @Override
    public abstract boolean handle(String key, String data);

    @Override
    public String getLogId() {
        String uuid = logId.get();
        if (uuid == null) {
            uuid = UUID.randomUUID().toString();
            logId.set(uuid);
        }
        return uuid;
    }

    @Override
    public String createLogId() {
        logId.set(UUID.randomUUID().toString());
        return logId.get();
    }

    @Override
    public String getLogData() {
        return data.get();
    }

    @Override
    public void setLogData(String str) {
        data.set(str);
    }
}